var express = require('express');
var router = express.Router();
const mongodb= require('../components/mongo');

/* GET home page. */
router.get('/',async function(req, res, next) {
	console.log(req.query);
	//without uid
	var m_aid = req.query.a_id;
	if(req.query.a_id==undefined){
		res.json(
			{
			    errno: 0,
			    errmsg: "",
			    data: {
			        res: false,
			    }
			}
		)
	}else{
		const result = await mongodb.find("Article",{a_id:m_aid});
		if(result.length==0){
			res.json(
				{
				    errno: 0,
				    errmsg: "",
				    data: {
				        res: false,
				    }
				}
			)
		}else{
			res.json(
				{
				    errno: 0,
				    errmsg: "",
				    data: {
				        res: true,
						article:result[0],
				    }
				}
			)
		}
	}
});


module.exports = router;